package com.junxonline.instant.common.entity.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * 公共分页响应对象
 *
 * @author JunX
 * @date 2021-06-25
 */
@Data
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class CommonRespPage<T> implements Serializable {

    /**
     * 页码
     */
    private Long totalCount;

    /**
     * 数据
     */
    private List<T> records;

    /**
     * 额外数据
     */
    private List expRecords;

    public CommonRespPage(Long totalCount, List<T> records) {
        this.totalCount = totalCount;
        this.records = records;
    }

    public static <T> CommonRespPage<T> success(IPage<T> page) {
        return new CommonRespPage<>(page.getTotal(), page.getRecords());
    }

    public static <T> CommonRespPage<T> success(IPage<T> page, List expRecords) {
        return new CommonRespPage<>(page.getTotal(), page.getRecords(), expRecords);
    }

}
